#include "NetCal.hpp"
#include "Protocol.hpp"
#include "TcpServer.hpp"
#include "Daemon.hpp"
#include <memory>

std::string defaulthandler(const std::string &word, InetAddrModule::InetAddr &addr)
{
    // LOG(LogLevel::DEBUG) << "回调到了defaulthandler";
    std::string s = "haha, ";
    s += word;
    return s;
}

void Usage(std::string proc)
{
    std::cerr << "Usage :" << proc << "service_ip  service_port" << std::endl;
}

int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(ARGV_ERROR);
    }

    std::cout << "服务器已经启动，已经是一个守护进程了" << std::endl;

    Daemon(0,0);
    // daemon(1,1);

    // Enable_File_Log_Strategy();

    // 1.顶层
    std::unique_ptr<Cal> calculate = std::make_unique<Cal>();

    // 2.协议层
    std::unique_ptr<Protocol> protocol = std::make_unique<Protocol>([&calculate](Request& req) ->Response
    {
        return (calculate->Execute(req));
    });

    // 3.服务器层
    std::unique_ptr<TcpServe> tsvr = std::make_unique<TcpServe>(std::stoi(argv[1]),
    [&protocol](std::shared_ptr<Socket>& sock,InetAddrModule::InetAddr& client)
    {
        protocol->GetRequest(sock,client);
    }
    );

    tsvr->Start();

    return 0;
}
